package p270jp.pxv.android.viewholder;

import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import com.bumptech.glide.load.engine.GlideException;
import p014ae.View$OnClickListenerC0090h7;
import p014ae.View$OnClickListenerC0151s;
import p045be.IllustDetailRecyclerAdapter;
import p047bg.C1124a;
import p140eo.C2973b;
import p165fo.C3114c;
import p172g5.DataSource;
import p187gl.C3359h;
import p270jp.pxv.android.R;
import p270jp.pxv.android.event.PlaybackUgoiraEvent;
import p270jp.pxv.android.legacy.model.PixivIllust;
import p270jp.pxv.android.legacy.model.PixivMetaUgoira;
import p270jp.pxv.android.view.PixivCircleProgressBar;
import p270jp.pxv.android.view.UgoiraView;
import p270jp.pxv.android.viewholder.CalcHeightViewHolder;
import p368ng.AbstractC5190t2;
import p577vl.UgoiraDownloader;
import p638y5.RequestListener;
import p639y6.C7297m;
import p664z5.Target;
import p677zi.PixivImageLoader;

/* renamed from: jp.pxv.android.viewholder.DetailUgoiraViewHolder */
/* loaded from: classes2.dex */
public class DetailUgoiraViewHolder extends CalcHeightViewHolder {
    private int parentViewWidth;
    private final PixivImageLoader pixivImageLoader;
    private ImageView previewImageView;
    private PixivCircleProgressBar progressBar;
    private ImageButton startButton;
    private ImageView stateChangeImageView;
    private UgoiraView ugoiraView;

    /* renamed from: jp.pxv.android.viewholder.DetailUgoiraViewHolder$UgoiraItem */
    /* loaded from: classes2.dex */
    public static class UgoiraItem extends CalcHeightViewHolder.CalcHeightItem {
        private PixivIllust illust;
        private IllustDetailRecyclerAdapter.AbstractC1093c onUgoiraStateChangeListener;

        public UgoiraItem(PixivIllust pixivIllust) {
            this.illust = pixivIllust;
        }

        public PixivIllust getIllust() {
            return this.illust;
        }

        public IllustDetailRecyclerAdapter.AbstractC1093c getOnUgoiraStateChangeListener() {
            return this.onUgoiraStateChangeListener;
        }

        public void setOnUgoiraStateChangeListener(IllustDetailRecyclerAdapter.AbstractC1093c cVar) {
            this.onUgoiraStateChangeListener = cVar;
        }
    }

    public DetailUgoiraViewHolder(View view) {
        super(view);
        this.ugoiraView = (UgoiraView) view.findViewById(R.id.ugoira_view);
        this.previewImageView = (ImageView) view.findViewById(R.id.ugoira_preview_image_view);
        this.startButton = (ImageButton) view.findViewById(R.id.ugoira_start_button);
        this.progressBar = (PixivCircleProgressBar) view.findViewById(R.id.ugoira_download_progressbar);
        this.stateChangeImageView = (ImageView) view.findViewById(R.id.ugoira_state_change_imageview);
        this.ugoiraView.setOnClickListener(new View$OnClickListenerC0151s(this, 24));
        this.parentViewWidth = C1124a.m10174r(view.getContext());
        this.pixivImageLoader = ((AbstractC5190t2) C2973b.m6512b(view.getContext(), AbstractC5190t2.class)).mo3376k();
    }

    /* renamed from: a */
    public static /* synthetic */ void m4448a(DetailUgoiraViewHolder detailUgoiraViewHolder, PixivIllust pixivIllust, PixivMetaUgoira pixivMetaUgoira) {
        detailUgoiraViewHolder.lambda$bind$0(pixivIllust, pixivMetaUgoira);
    }

    /* renamed from: d */
    public static /* synthetic */ void m4447d(DetailUgoiraViewHolder detailUgoiraViewHolder, PixivIllust pixivIllust, View view) {
        detailUgoiraViewHolder.lambda$bind$1(pixivIllust, view);
    }

    /* renamed from: downloadUgoira */
    public void lambda$bind$0(final PixivIllust pixivIllust, final PixivMetaUgoira pixivMetaUgoira) {
        this.startButton.setVisibility(8);
        this.progressBar.setVisibility(0);
        UgoiraDownloader bVar = new UgoiraDownloader(pixivIllust.f19079id, pixivMetaUgoira);
        bVar.f29166f = new UgoiraDownloader.AbstractC6851a() { // from class: jp.pxv.android.viewholder.DetailUgoiraViewHolder.2
            @Override // p577vl.UgoiraDownloader.AbstractC6851a
            public void onDownloadFailed() {
            }

            @Override // p577vl.UgoiraDownloader.AbstractC6851a
            public void onDownloaded() {
                DetailUgoiraViewHolder.this.progressBar.setVisibility(8);
                DetailUgoiraViewHolder.this.previewImageView.setVisibility(8);
                DetailUgoiraViewHolder.this.ugoiraView.setVisibility(0);
                DetailUgoiraViewHolder.this.ugoiraView.setWorkId(pixivIllust.f19079id);
                DetailUgoiraViewHolder.this.ugoiraView.setFrames(pixivMetaUgoira.getFrames());
            }

            @Override // p577vl.UgoiraDownloader.AbstractC6851a
            public void onProgressChanged(float f) {
                DetailUgoiraViewHolder.this.progressBar.setProgress(((float) DetailUgoiraViewHolder.this.progressBar.getMax()) * f);
            }
        };
        bVar.execute(new Void[0]);
    }

    /* renamed from: e */
    public static /* synthetic */ void m4446e(DetailUgoiraViewHolder detailUgoiraViewHolder, boolean z) {
        detailUgoiraViewHolder.lambda$bind$2(z);
    }

    public static int getLayoutRes() {
        return R.layout.view_illust_detail_ugoira;
    }

    public /* synthetic */ void lambda$bind$1(PixivIllust pixivIllust, View view) {
        C3114c.m6284b().m6280f(new PlaybackUgoiraEvent(pixivIllust.f19079id, new C7297m(this, pixivIllust, 8)));
    }

    public /* synthetic */ void lambda$bind$2(boolean z) {
        if (z) {
            this.ugoiraView.m4459c(false);
        } else {
            this.ugoiraView.m4460b(false);
        }
    }

    private void showUgoiraStateChangeAnimation(boolean z) {
        this.stateChangeImageView.setImageResource(z ? R.drawable.ugoira_stop : R.drawable.ugoira_start);
        this.stateChangeImageView.startAnimation(AnimationUtils.loadAnimation(this.itemView.getContext(), R.anim.ugoira_state_change));
    }

    @Override // p270jp.pxv.android.viewholder.BaseViewHolder
    public void bind(Object obj) {
        super.bind(obj);
        final UgoiraItem ugoiraItem = (UgoiraItem) obj;
        PixivIllust illust = ugoiraItem.getIllust();
        String large = illust.metaSinglePage.getOriginalImageUrl() == null ? illust.imageUrls.getLarge() : illust.metaSinglePage.getOriginalImageUrl();
        int i = illust.width;
        float f = ((float) this.parentViewWidth) / ((float) i);
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams((int) (((float) i) * f), (int) (f * ((float) illust.height)));
        this.ugoiraView.setLayoutParams(layoutParams);
        this.previewImageView.setLayoutParams(layoutParams);
        this.pixivImageLoader.m55k(this.itemView.getContext(), large, this.previewImageView, new RequestListener<Drawable>() { // from class: jp.pxv.android.viewholder.DetailUgoiraViewHolder.1
            @Override // p638y5.RequestListener
            public boolean onLoadFailed(GlideException glideException, Object obj2, Target<Drawable> iVar, boolean z) {
                return false;
            }

            public boolean onResourceReady(Drawable drawable, Object obj2, Target<Drawable> iVar, DataSource aVar, boolean z) {
                if (DetailUgoiraViewHolder.this.ugoiraView.getVisibility() != 0) {
                    DetailUgoiraViewHolder.this.startButton.setVisibility(0);
                }
                DetailUgoiraViewHolder.this.postCalcViewHeight(ugoiraItem);
                return false;
            }
        });
        this.startButton.setOnClickListener(new View$OnClickListenerC0090h7(this, illust, 7));
        ugoiraItem.setOnUgoiraStateChangeListener(new C3359h(this, 4));
    }

    public void onUgoiraViewClick(View view) {
        showUgoiraStateChangeAnimation(!this.ugoiraView.m4461a());
        if (this.ugoiraView.m4461a()) {
            this.ugoiraView.m4459c(true);
        } else {
            this.ugoiraView.m4460b(true);
        }
    }
}
